package com.pedro.streamer;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.pedro.streamer.manager.VideoArrManager;
import com.tencent.bugly.crashreport.CrashReport;
import com.tencent.mmkv.MMKV;

import java.lang.ref.WeakReference;

public class BmiBaseApp extends Application {
    private final static String TAG = BmiBaseApp.class.getSimpleName();
    private static BmiBaseApp mInstance;

    private static WeakReference<Activity> mTopActivity;

    public static BmiBaseApp getInstance() {
        if (mInstance == null) {
            mInstance = new BmiBaseApp();
        }
        return mInstance;
    }

    public BmiBaseApp() {

    }

    public static Activity getTopActivity() {
        if (mTopActivity == null) {
            return null;
        } else {
            return mTopActivity.get();
        }
    }

    @Override
    public void onCreate() {
        super.onCreate();

        mInstance = this;
        CrashReport.initCrashReport(getApplicationContext(), "ab20f9158d", false);
        MMKV.initialize(this);
        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {

            }

            @Override
            public void onActivityStarted(@NonNull Activity activity) {
                mTopActivity = new WeakReference<>(activity);
            }

            @Override
            public void onActivityResumed(@NonNull Activity activity) {

            }

            @Override
            public void onActivityPaused(@NonNull Activity activity) {

            }

            @Override
            public void onActivityStopped(@NonNull Activity activity) {
                if (activity == getTopActivity()) {
                    mTopActivity = null;
                }
            }

            @Override
            public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) {

            }

            @Override
            public void onActivityDestroyed(@NonNull Activity activity) {

            }
        });



    }
}
